package com.qf.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.dao.CityDao;
import com.qf.entity.City;
import com.qf.service.CityService;
import com.qf.util.PinyinUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * (City)表服务实现类
 *
 * @author makejava
 * @since 2020-11-12 09:40:16
 */
@Service("cityService")
@Slf4j
public class CityServiceImpl extends ServiceImpl<CityDao, City> implements CityService {

    @Override
    @Transactional
    public boolean save(City entity) {
        log.info("[cityinsert] 城市服务业务层 保存城市信息！参数：" + entity);
        //根据城市名称生成城市拼音
        String pinyin = PinyinUtil.string2Pinyin(entity.getCityName());
        entity.setCityPinyin(pinyin);
        return super.save(entity);
    }

    /**
     * 该方法有线程安全的问题
     * @param cid
     * @return
     */
    @Override
    @Transactional
    public boolean incrCityHotalNumber(Integer cid) {
        City city = super.getById(cid);
        city.setHotalNumber(city.getHotalNumber() + 1);
        boolean flag = super.updateById(city);
        return flag;
    }
}